package com.uplooking.service;

import com.uplooking.dao.DBUtil;
import com.uplooking.domain.AriticalManageBean;
import com.uplooking.domain.ResponseBean;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

public class QueryArticalManage {
    public List<AriticalManageBean> getArticleAll(Integer page, Integer counts) {
        DataSource c3P0ConnctionPool = DBUtil.getC3P0ConnctionPool();
        QueryRunner queryRunner = new QueryRunner(c3P0ConnctionPool);
        try {
            Object[] parm = {(page - 1) * counts, counts};
            List<AriticalManageBean> list = queryRunner.query("select * from artical where id limit ?,?", new BeanListHandler<AriticalManageBean>(AriticalManageBean.class), parm);
            System.out.println(list);
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}